// pages/save-image/index.ts
Page({

    /**
     * 页面的初始数据
     */
    data: {
        url: "https://wechat.weixinzjit.com/costa/public/uploads/images/20190109/67b16149693920598435315fd0d5ab3e.jpg"
    },
    // 将网络地址文件转换为本地路径保存
    saveImage () {
        wx.getImageInfo({
            src: this.data.url,
            success (res) {
                wx.saveImageToPhotosAlbum({
                    filePath: res.path,
                    success(res) { 
                        console.log(res)
                    }
                })
            }
        })
    },
    // 保存图片需要先查看权限有图片保存权限再保存
    authImage () {
        wx.getSetting({
            success: (res) => {
                if (res.authSetting['scope.writePhotosAlbum']) {
                    this.saveImage()
                } else {
                    // 先用原生的授权，如果原生的拒绝了，拉起系统的
                    wx.authorize({
                        scope: 'scope.writePhotosAlbum',
                        success: () => {
                            this.saveImage()
                        },
                        fail: () => {
                            wx.showModal({
                                title: '提示',
                                content: '保存图片需要开启相应的权限',
                                success: (res) => {
                                    if (res.confirm) {
                                        wx.openSetting({
                                            success: (res) => {
                                                this.saveImage()
                                            }
                                        })
                                    }
                                }
                            })
                        }
                    })
                    
                }
                
            }
        })
        
    },
    

})